package com.jzj.servlet;
import com.jzj.dao.BaseDao;
import com.jzj.entity.Shop;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/ControlServlet")
public class ControlServlet extends HttpServlet {
    @Override
    public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
       String name=req.getParameter("name");
       String in_price=req.getParameter("in_price");
       String price=req.getParameter("price");
       String count=req.getParameter("count");
       String status=req.getParameter("status");

       BaseDao baseDao = new BaseDao();

       Shop shop = new Shop(name,Double.parseDouble(in_price),Double.parseDouble(price),Integer.parseInt(count),status);

        if (baseDao.findSql(name)){
            baseDao.updataSql(shop);
            req.setAttribute("msg","找到name");
        }else{
            baseDao.addSql(shop);
            req.setAttribute("status",status);
        }
        req.getRequestDispatcher("jsp/control.jsp").forward(req,res);
    }
}
